﻿using System;
using System.Collections.Generic;

namespace NeroConnect.Network
{
	/// <summary>Provides a simple, programmatically controlled HTTP protocol listener.</summary>
	public interface IListener : IDisposable
	{
		/// <summary>Gets a value that indicates whether System.Net.HttpListener has been started.</summary>
		/// <value>true if the System.Net.HttpListener was started; otherwise, false.</value>
		bool IsListening { get; }

		/// <summary>Gets or sets a System.Boolean value that specifies whether your application receives exceptions that occur when an IListener sends the response to the client.</summary>
		/// <value>true if this IListener should not return exceptions that occur when sending the response to the client; otherwise false. The default value is false.</value>
		bool IgnoreWriteExceptions { get; set; }

		/// <summary>Shuts down the IListener object immediately, discarding all currently queued requests.</summary>
		void Abort();

		/// <summary>Begins asynchronously retrieving an incoming request.</summary>
		/// <param name="callback">An System.AsyncCallback delegate that references the method to invoke when a client request is available.</param>
		/// <param name="state">A user-defined object that contains information about the operation. This object is passed to the callback delegate when the operation completes.</param>
		/// <returns>An System.IAsyncResult object that indicates the status of the asynchronous operation.</returns>
		/// <exception cref="System.Net.HttpListenerException">A Win32 function call failed. Check the exception's System.Net.HttpListenerException.ErrorCode property to determine the cause of the exception.</exception>
		/// <exception cref="System.InvalidOperationException">This object has not been started or is currently stopped.</exception>
		/// <exception cref="System.ObjectDisposedException">This object is closed.</exception>
		IAsyncResult BeginGetContext(AsyncCallback callback, object state);

		/// <summary>Shuts down the IListener.</summary>
		void Close();

		/// <summary>Completes an asynchronous operation to retrieve an incoming client request.</summary>
		/// <param name="asyncResult">An System.IAsyncResult object that was obtained when the asynchronous operation was started.</param>
		/// <returns>An IListenerContext object that represents the client request.</returns>
		/// <exception cref="System.Net.HttpListenerException">A Win32 function call failed. Check the exception's System.Net.HttpListenerException.ErrorCode property to determine the cause of the exception.</exception>
		/// <exception cref="System.ArgumentException">asyncResult was not obtained by calling the BeginGetContext(System.AsyncCallback,System.Object) method.</exception>
		/// <exception cref="System.ArgumentNullException">asyncResult is null.</exception>
		/// <exception cref="System.InvalidOperationException">The EndGetContext(System.IAsyncResult) method was already called for the specified asyncResult object.</exception>
		/// <exception cref="System.ObjectDisposedException">This object is closed.</exception>
		IListenerContext EndGetContext(IAsyncResult asyncResult);

		/// <summary>Waits for an incoming request and returns when one is received.</summary>
		/// <returns>An IListenerContext object that represents a client request.</returns>
		/// <exception cref="System.Net.HttpListenerException">A Win32 function call failed. Check the exception's System.Net.HttpListenerException.ErrorCode property to determine the cause of the exception.</exception>
		/// <exception cref="System.InvalidOperationException">This object has not been started or is currently stopped.-or-The IListener does not have any Uniform Resource Identifier (URI) prefixes to respond to. See Remarks.</exception>
		/// <exception cref="System.ObjectDisposedException">This object is closed.</exception>
		[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1024:UsePropertiesWhereAppropriate")]
		IListenerContext GetContext();

		/// <summary>Allows this instance to receive incoming requests.</summary>
		/// <exception cref="System.Net.HttpListenerException">A Win32 function call failed. Check the exception's System.Net.HttpListenerException.ErrorCode property to determine the cause of the exception.</exception>
		/// <exception cref="System.ObjectDisposedException">This object is closed.</exception>
		void Start();

		/// <summary>Causes this instance to stop receiving incoming requests.</summary>
		/// <exception cref="System.ObjectDisposedException">This object has been closed.</exception>
		[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1716:IdentifiersShouldNotMatchKeywords", MessageId = "Stop")]
		void Stop();

		/// <summary>Gets a list of the local IP addresses of all network adapters available on this computer.</summary>
		/// <value>List of local IPAddresses of all network adapters</value>
		IList<System.Net.IPAddress> LocalIPAddresses { get; }
	}
}
